package com.gdufe.firesafe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gdufe.firesafe.dao.BuildingDao;
import com.gdufe.firesafe.model.entity.BuildingEntity;
import com.gdufe.firesafe.service.BuildingService;
import com.gdufe.firesafe.utils.PageUtils;
import com.gdufe.firesafe.utils.Query;
import com.gdufe.firesafe.model.vo.BuildingVO;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Service("buildingService")
public class BuildingServiceImpl extends ServiceImpl<BuildingDao, BuildingEntity> implements BuildingService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BuildingEntity> page = this.page(
                new Query<BuildingEntity>().getPage(params),
                new QueryWrapper<BuildingEntity>()
        );

        return new PageUtils(page);
    }

    //获取楼栋名
    @Override
    public List<BuildingVO> getBuildings() {
        List<BuildingEntity> buildings = super.baseMapper.selectList(null);
        List<BuildingVO> vos=new ArrayList<>();
        for (BuildingEntity building : buildings){
            BuildingVO vo=new BuildingVO();
            vo.setValue(building.getId());
            vo.setLabel(building.getName());
            vos.add(vo);
        }
        return vos;
    }

    @Override
    public BuildingEntity getById(Serializable id) {
        return super.getById(id);
    }

    @Override
    public boolean save(BuildingEntity entity) {
        return super.save(entity);
    }

    @Override
    public boolean updateById(BuildingEntity entity) {
        return super.updateById(entity);
    }

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }
}
